Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / ui / src / commonMain / kotlin / org / meshtastic / core / ui / util / PermissionStatus.kt

Displaying Raw • Download

core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/util/PermissionStatus.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 4.17 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ui.util

Tff7b72import T7ee787androidx.compose.runtime.Stable

T8b949e/**
* The UX-relevant state of a runtime permission, as recommended by the Android permissions guidance
* (https://developer.android.com/training/permissions/requesting). Declared in lifecycle order.
* - [NOT_REQUESTED] — the user has never been prompted; request directly (no rationale needed yet).
* - [DENIED_CAN_RETRY] — the user denied once but the system will still show the dialog; show a rationale and offer to
* re-request.
* - [PERMANENTLY_DENIED] — the system will no longer show the dialog ("Don't allow" twice, or "Don't ask again"); the
* only recovery is the app's settings screen.
* - [GRANTED] — the permission is held; proceed.
*/
Tff7b72enum Tff7b72class T56d364PermissionStatus Tb4b4b4{
Te6edf3NOT_REQUESTEDTb4b4b4,
Te6edf3DENIED_CAN_RETRYTb4b4b4,
Te6edf3PERMANENTLY_DENIEDTb4b4b4,
Te6edf3GRANTEDTb4b4b4,
Tb4b4b4}

T8b949e/**
* Pure classifier for a runtime permission's UX state. Kept platform-agnostic and side-effect-free so it can be
* unit-tested in `commonTest` without an Android `Activity`.
*
* **Invariant:** [hasRequested] MUST reflect a *completed* request — it should be persisted from the launcher's result
* callback, never merely when `launch()` is invoked. On Android, `launch()` does not show a dialog once a permission is
* permanently denied, and a user can background the app before a dialog resolves; setting the flag pre-emptively would
* misclassify a first-run user as [PERMANENTLY_DENIED].
*
* Note that [shouldShowRationale] is `false` both *before* the first prompt and *after* a permanent denial — which is
* exactly why [hasRequested] is required to disambiguate the two cases.
*/
Tff7b72fun Td2a8ffcomputePermissionStatusTb4b4b4(Te6edf3grantedTb4b4b4: Tffa657BooleanTb4b4b4, Te6edf3hasRequestedTb4b4b4: Tffa657BooleanTb4b4b4, Te6edf3shouldShowRationaleTb4b4b4: Tffa657BooleanTb4b4b4)Tb4b4b4: Te6edf3PermissionStatus Tff7b72=
Tff7b72when Tb4b4b4{
Te6edf3granted Tff7b72-Tff7b72> Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTED
Tff7b72!Te6edf3hasRequested Tff7b72-Tff7b72> Te6edf3PermissionStatusTb4b4b4.Te6edf3NOT_REQUESTED
Te6edf3shouldShowRationale Tff7b72-Tff7b72> Te6edf3PermissionStatusTb4b4b4.Te6edf3DENIED_CAN_RETRY
Tff7b72else Tff7b72-Tff7b72> Te6edf3PermissionStatusTb4b4b4.Te6edf3PERMANENTLY_DENIED
Tb4b4b4}

T8b949e/**
* A reactive snapshot of a runtime permission plus the actions a caller can take. Produced by the
* `rememberXxxPermissionState()` composables and recomputed on `ON_RESUME` so it stays fresh when the user returns from
* a permission dialog or the system settings screen.
*
* Intentionally NOT a `data class`: the lambda members would give `equals`/`hashCode` reference semantics, advertising
* value equality the type cannot honor. Callers read [status]/[isGranted] and invoke the actions; they do not compare
* instances.
*/
Tf0883e@Stable
Tff7b72class T56d364PermissionUiStateTb4b4b4(Tff7b72val Te6edf3statusTb4b4b4: Te6edf3PermissionStatusTb4b4b4, Tff7b72val Te6edf3requestTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4, Tff7b72val Te6edf3openAppSettingsTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3isGrantedTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3status Tff7b72=Tff7b72= Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTED
Tb4b4b4}

T8b949e/** A constant [PermissionUiState] for platforms / API levels where a permission is not gated at runtime. */
Tff7b72fun Td2a8ffgrantedPermissionUiStateTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3PermissionUiState Tff7b72=
Te6edf3PermissionUiStateTb4b4b4(Te6edf3status Tff7b72= Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTEDTb4b4b4, Te6edf3request Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4, Te6edf3openAppSettings Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4)

T8b949e/**
* Reduces the per-permission grant [results] of a permission group to a single granted flag.
*
* @param requireAll when true every permission must be granted (e.g. Bluetooth scan + connect); when false a single
* grant suffices (e.g. location, where a coarse-only grant is an accepted degraded mode).
*/
Tff7b72fun Td2a8ffisPermissionGroupGrantedTb4b4b4(Te6edf3resultsTb4b4b4: Te6edf3ListTff7b72<Tffa657BooleanTff7b72>Tb4b4b4, Te6edf3requireAllTb4b4b4: Tffa657BooleanTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72=
Tff7b72if Tb4b4b4(Te6edf3requireAllTb4b4b4) Te6edf3resultsTb4b4b4.Te6edf3all Tb4b4b4{ Tffa657it Tb4b4b4} Tff7b72else Te6edf3resultsTb4b4b4.Te6edf3any Tb4b4b4{ Tffa657it Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.07s